package com.lhb.controller.admin;

import com.lhb.dto.StudentAddDTO;
import com.lhb.dto.StudentEditDTO;
import com.lhb.dto.StudentPageQueryDTO;
import com.lhb.result.PageResult;
import com.lhb.result.Result;
import com.lhb.service.StudentService;
import com.lhb.vo.StudentGetByIdVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/student")
@Slf4j
@Api(tags = "学生相关接口")
public class StudentController {

    @Autowired
    StudentService studentService;



    @PostMapping("/pageQuery")
    @ApiOperation("分页查询")
    public Result<PageResult> pageQuery(@RequestBody StudentPageQueryDTO studentPageQueryDTO)
    {
        log.info("学生分页查询:{}", studentPageQueryDTO);

        PageResult pageResult= studentService.pageQuery(studentPageQueryDTO);


        return Result.success(pageResult);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询用户")
    public Result<StudentGetByIdVO> getById(@PathVariable Long id)
    {

           log.info("根据id:{}查询用户",id);

         StudentGetByIdVO studentGetByIdVO=studentService.getById(id);



        return Result.success(studentGetByIdVO);
    }
    @PutMapping
    @ApiOperation("编辑")
    public Result update(@RequestBody StudentEditDTO studentEditDTO)
    {
        log.info("编辑id为:{}的学生",studentEditDTO.getId());

        studentService.update(studentEditDTO);



        return Result.success();
    }


    @PostMapping
    @ApiOperation("添加用户")
    public Result save(@RequestBody StudentAddDTO studentAddDTO)
    {
        log.info("添加用户:{}",studentAddDTO);

        studentService.save(studentAddDTO);




        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("删除用户")
    public Result delete(@RequestParam List<Long> ids)
    {
        log.info("删除用户:{}", ids);

        studentService.delete(ids);


        return Result.success();
    }

}
